package com.hhdys.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hhdys.annotation.Access;
import com.hhdys.model.WebSet;
import com.hhdys.service.WebSetService;

@Controller
@RequestMapping("/admin/webset")
@Access("属性设置")
public class WebSetAction {
	@Autowired
	private WebSetService service;

	@RequestMapping("/showWebSets")
	@Access("查看")
	public String showWebSets(Model model) {
		List<WebSet> list = service.selectWebSets();
		model.addAttribute("list", list);
		model.addAttribute("parentSet", service.showParentSetJson(service.selectParentWebSets()));
		return "admin/webset/webset";
	}
	
	@RequestMapping("/add")
	@ResponseBody
	@Access("添加")
	public String addSet(WebSet webSet) {
		if (service.addWebSet(webSet) > 0) {
			return "success";
		}
		return "error";
	}

	@RequestMapping("/del")
	@ResponseBody
	@Access("删除")
	public String delSet(String ids) {
		service.delWebSet(ids);
		return "success";
	}

	@RequestMapping("/edit")
	@ResponseBody
	@Access("编辑")
	public String edit(WebSet webSet) {
		return service.editWebSet(webSet) > 0 ? "success" : "error";
	}

	/**
	 * @return the service
	 */
	public WebSetService getService() {
		return service;
	}

	/**
	 * @param service
	 *            the service to set
	 */
	public void setService(WebSetService service) {
		this.service = service;
	}

}
